package com.spc.controller;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.cdg.util.Json;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.spc.bean.Bis_opinion;
import com.spc.service.Bis_opinionService;

@Controller
@RequestMapping("bisopinion")
public class Bis_opinionController {
 
	@Autowired
	private Bis_opinionService bis_opinionService;
	
	@RequestMapping("/list")
	public String list(Model model,HttpServletRequest  request,@RequestParam(value="page",defaultValue="1")int page){
		Map<String, Object> map = initMap(request);
		PageHelper.startPage(page, 4);
		List<Bis_opinion> list =this.bis_opinionService.listAll(map);
		PageInfo<Bis_opinion> info=new PageInfo<>(list);
		model.addAttribute("info",info);
		return "spc/Bis_opinionList";
	} 
	
	@RequestMapping("/parameter")
	public String parameterList(){
		return "spc/parameterList";
	}
	
	private Map<String, Object> initMap(HttpServletRequest request) {
		Map<String,Object> map=new HashMap<String,Object>();
		String mobile=request.getParameter("mobile");//鎵嬫満鍙�
		String content=request.getParameter("content");//鍐呭
		String create_time1=request.getParameter("create_time1");//鍙戣捣鏃堕棿1
		String create_time2=request.getParameter("create_time2");//鍙戣捣鏃堕棿2
		if(Tools.isNotNull(mobile)){
			map.put("mobile", mobile);
			request.setAttribute("mobile",mobile);
		}
		if(Tools.isNotNull(content)){
			map.put("content",content );
			request.setAttribute("content",content);
		}  
		if(Tools.isNotNull(create_time1)){
			map.put("create_time1",create_time1 );
			request.setAttribute("create_time1",create_time1);
		}
		if(Tools.isNotNull(create_time2)){
			map.put("create_time2",create_time2 );
			request.setAttribute("create_time2",create_time2);
		}
		return map;
	}
	
	@RequestMapping("delete")
	public String datele(String ids){
		bis_opinionService.delete(ids);//鍙栧惊鐜��
		return "redirect:/bisopinion/list";
	}
	
	@RequestMapping("select")
	//@ResponseBody
	public void  select6(String opinion_id,Model model,HttpServletResponse response){
		Bis_opinion op=this.bis_opinionService.getById(opinion_id);
		String jsonString=Json.getJson(op);
		System.out.println(op);
		try {
			PrintWriter outPrintWriter=response.getWriter();
			outPrintWriter.print(jsonString);
			outPrintWriter.flush();
			outPrintWriter.close(); 
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
} 
